<template>
	<view class="master-income-record" :style="{background:pageColor,paddingTop:options.type===1?'':'1rpx'}">
		<fixed v-if="options.type==1">
			<tab @change="handerTabChange" :list="tabList" :activeIndex="activeIndex*1" :activeColor="primaryColor"
				color="#999" lineClass="sm" width="50%" height="100rpx"></tab>
		</fixed>
		<view class="fill-base pd-lg mt-md ml-md mr-md radius-16" v-for="(item,index) in list.data" :key="index">
			<view class="flex-between text-bold">
				<view class="f-mini-title c-title">ID：{{item.id}}</view>
				<view class="f-title" :style="{color:item.is_add?primaryColor:'#F1381F'}">
					{{item.is_add?'+':'-'}}¥{{item.cash}}
				</view>
			</view>
			<view class="flex-between f-paragraph c-paragraph mt-lg">
				<view>操作者：{{item.create_user}}</view>
				<view class="">现余额：¥{{item.after_cash}}</view>
			</view>
			<view class="f-caption c-caption mt-lg">{{item.create_time}}</view>
			<view class="flex-warp f-paragraph c-paragraph mt-lg pt-lg b-1px-t">
				<view style="width: 85rpx;">备注：</view>
				<view style="width: calc(100% - 85rpx);color: #303030;">
					<view v-if="options.type==3">
						<block v-if="item.admin_type>0">给
							<span class="text-bold" style="padding:0 6rpx">{{item.admin_update_name||'-'}}</span>
						</block>
						{{adminTypeList[item.admin_type]}}
						<block v-if="item.admin_type>0">
							<span style="margin-left: 6rpx;"
								:style="{color:item.is_add?'#F1381F':primaryColor}">{{item.is_add?'-':'+'}}¥{{item.cash}}</span>，自己账户
						</block>
						<span style="margin-left: 6rpx;"
							:style="{color:item.is_add?primaryColor:'#F1381F'}">{{item.is_add?'+':'-'}}¥{{item.cash}}</span>
					</view>
					<text decode="emsp" style="word-break:break-all;" v-else>{{item.text}}
					</text>
				</view>
			</view>
		</view>
		<load-more :noMore="list.current_page>=list.last_page&&list.data.length>0" :loading="loading">
		</load-more>
		<abnor v-if="!loading&&list.data.length<=0&&list.current_page==1" :isCenter="true"></abnor>

		<view class="space-footer"></view>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		data() {
			return {
				options: {},
				activeIndex: 0,
				tabList: [{
					title: '服务费修改记录',
					id: 1
				}, {
					title: '车费修改记录',
					id: 2
				}],
				adminTypeList: {
					'-1': '自主充值',
					'-2': `${this.$t('action.resellerName')}推荐费`,
					0: '修改余额',
					1: `${this.$t('action.attendantName')}服务费`,
					2: `${this.$t('action.attendantName')}车费`,
					3: `${this.$t('action.agentName')}余额`,
					4: `${this.$t('action.resellerName')}余额`,
					5: `${this.$t('action.channelName')}余额`,
					6: '业务员余额',
					7: `${this.$t('action.brokerName')}余额`,
					8: '平台管理员余额',
					9: '补贴车费'
				},
				param: {
					page: 1,
					type: 1
				},
				list: {
					data: []
				},
				loading: true,
			}
		},
		computed: mapState({}),
		async onLoad(options) {
			this.options = options
			this.activeIndex = 0
			this.$util.setNavigationBarColor({
				bg: this.primaryColor
			})
			await this.initIndex()
		},
		onPullDownRefresh() {
			// #ifndef APP-PLUS
			uni.showNavigationBarLoading()
			// #endif
			this.initRefresh()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			if (this.list.current_page >= this.list.last_page || this.loading) return;
			this.param.page = this.param.page + 1;
			this.loading = true;
			this.getList();
		},
		methods: {
			...mapMutations([]),
			async initIndex(refresh = false) {
				await this.getList()
				// #ifdef H5
				if (!refresh) {
					this.$jweixin.hideOptionMenu()
				}
				// #endif
			},
			initRefresh() {
				this.param.page = 1
				this.initIndex(true)
			},
			async getList() {
				let {
					list: oldList,
					param,
				} = this
				let {
					type
				} = this.options
				let methodArr = {
					1: ['technician', 'updateCoachCashList'],
					3: ['agent', 'updateCoachCashList'],
					8: ['adminuser', 'updateCoachCashList']
				}
				if (type * 1 != 1) {
					delete param.type
				}
				let methodKey = methodArr[type][0]
				let methodModel = methodArr[type][1]
				let newList = await this.$api[methodKey][methodModel](param);
				if (this.param.page == 1) {
					this.list = newList
				} else {
					newList.data = oldList.data.concat(newList.data)
					this.list = newList
				}
				this.loading = false
				this.$util.hideAll()
			},
			handerTabChange(index) {
				this.activeIndex = index
				let {
					id
				} = this.tabList[index]
				this.param.type = id
				this.param.page = 1
				this.getList()
			}
		}
	}
</script>


<style lang="scss">
	.master-income-record {

		.mine-menu-list {

			.money-info {
				font-size: 50rpx;

				.money {
					font-size: 70rpx;
				}
			}

		}

		.list-item {
			.item-tag {
				width: 24rpx;
				height: 24rpx;
			}
		}
	}
</style>